#include "base/count_down_cond.h"
#include "base/eventloop.h"
#include "base/log.h"
#include "base/thread.h"

#include "base/eventloopthread.h"
namespace net_tools{

Eventloopthread::Eventloopthread(eventloop_func func_,int size,std::string thread_name)
  :eventloop_size(size),
   func_thread_in(std::move(func_)),
   eventloop_(new net_tools::Eventloop(eventloop_size))
{
  if(!func_thread_in){
    NT_LOG_INFO << "No thread to do Default" << NT_LOG_ENDL;
    default_func_ = [this]{eventloop_->Loop();};
  } else {
    default_func_ = [this]{func_thread_in(eventloop_);}; //lambda
  }
  thread_ = new base::Thread(std::move(default_func_),thread_name);
  thread_->Start();
  pthread_detach(thread_->GetThreadid());
};
net_tools::Eventloop* Eventloopthread::Get_eventloop_() const {
  return eventloop_;
};

} // namespace net_toolsE